package com.alageek.study;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class FileFindVisitor extends Visitor {

    private final String suffixString;

    private final List<File> list = new ArrayList<>();

    public FileFindVisitor(String suffixString){
        this.suffixString = suffixString;
    }

    @Override
    public void visit(File file) {
        //System.out.println(file.getName());
        if(file.getName().contains(suffixString)){
            list.add(file);
        }
    }

    @Override
    public void visit(Directory directory) {
        Iterator<Entry> iterator = directory.iterator();
        while (iterator.hasNext()){
            Entry entry = iterator.next();
            entry.accept(this);
        }
    }

    public Iterator<File> getFoundFiles(){

        return list.iterator();
    }
}
